// 引入二次封装的 axios
import request from "@/utils/request"
// 引入接口数据类型
import {
    MemberInfoData, UserCodeData, LoginData, UserInfoData, WxLoginData, OrderInfoData, CancelOrderData,
    CreateNativeData, CertificationTypeResponse, UserAuahData, UserOrderInfoResponse, PatientInfoResponse, OrderStatusResponse, CityResponse, AddOrUpdateData
} from "./type";

// 枚举请求地址
enum API {
    // 获取验证码的地址
    GETUSERCODE_URL = "/sms/send/",
    // 接收登陆信息的地址
    USERLOGIN_URL = "/user/login",
    // 获取微信扫码登录需要参数的地址
    WXLOGIN_URL = "/user/weixin/getLoginParam/",
    // 获取订单的地址
    ORDERINFO_URL = "/order/orderInfo/auth/getOrderInfo/",
    // 取消订单的地址
    CANCELORDER_URL = "/order/orderInfo/auth/cancelOrder/",
    // 下单生成二维码地址
    CREATENATIVE_URL = "/order/weixin/createNative/",
    // 查询支付状态
    PAYSTATUS_URL = "/order/weixin/queryPayStatus/",
    // 会员信息
    USERINFO_URL = "/user/auth/getUserInfo",
    // 获取证件类型
    CERTIFICATIONTYPE_URL = "/cmn/dict/findByDictCode/",
    // 会员认证
    USERAUAH_URL = "/user/auth/userAuah",
    // 获取用户订单号的地址
    USERORDERINFO_URL = "/order/orderInfo/auth/",
    // 获取所有就诊人
    FINDALL_URL = "/user/patient/auth/findAll",
    // 获取所有订单状态
    STATUSLIST_URL = "/order/orderInfo/auth/getStatusList",
    // 获取城市的接口
    CITY_URL = "/cmn/dict/findByParentId/",
    // 新增就诊人的接口
    ADDVISITOR_URL = "/user/patient/auth/save",
    // 修改就诊人的接口
    UPDATEVISITOR_URL = "/user/patient/auth/update",
    // 删除就诊人的接口
    DELETEVISITOR_URL = "/user/patient/auth/remove/"
}

// 获取验证码的接口
export const reqUserCode = (phone: string) => request.get<any, UserCodeData>(API.GETUSERCODE_URL + phone);
// 发送用户登录信息
export const reqUserLogin = (data: LoginData) => request.post<any, UserInfoData>(API.USERLOGIN_URL, data)
// 获取用户扫码登录需要的参数
export const reqWxLogin = (wxRedirectUri: string) => request.get<any, WxLoginData>(API.WXLOGIN_URL + `?wxRedirectUri=${wxRedirectUri}`)
// 获取订单的接口
export const reqOrderInfo = (id: number) => request.get<any, OrderInfoData>(API.ORDERINFO_URL + id)
// 取消订单的接口
export const reqCancelOrder = (id: number) => request.get<any, CancelOrderData>(API.CANCELORDER_URL + id)
// 下单生成二维码的接口
export const reqCreateNative = (id: number) => request.get<any, CreateNativeData>(API.CREATENATIVE_URL + id)
// 查询支付状态的接口
export const reqPayStatus = (id: number) => request.get<any>(API.PAYSTATUS_URL + id)
// 获取会员信息的接口
export const reqMemberInfo = () => request.get<any, MemberInfoData>(API.USERINFO_URL)
// 获取证件类型的接口
export const reqCertificationType = (dictCode: string = "CertificatesType") => request.get<any, CertificationTypeResponse>(API.CERTIFICATIONTYPE_URL + dictCode)
// 发送会员认证信息
export const reqUserAuah = (data: UserAuahData) => request.post(API.USERAUAH_URL, data)
// 获取用户订单号 
export const reqUserOrderInfo = (page: number, limit: number, patientId: string, orderStatus: string) => request.get<any, UserOrderInfoResponse>(API.USERORDERINFO_URL + `${page}/${limit}?patientId=${patientId}&orderStatus=${orderStatus}`)
// 获取所有就诊人
export const reqFindAll = () => request.get<any, PatientInfoResponse>(API.FINDALL_URL)
// 获取所有订单状态
export const reqStatusList = () => request.get<any, OrderStatusResponse>(API.STATUSLIST_URL)
// 获取城市 
export const reqCity = (id: number) => request.get<any, CityResponse>(API.CITY_URL + id)
// 新增/修改就诊人
export const reqAddOrUpdateVisitor = (data: AddOrUpdateData) => {
    if (data.id) {
        return request.put(API.UPDATEVISITOR_URL, data)
    } else {
        return request.post(API.ADDVISITOR_URL, data)
    }
}
// 删除某一个就诊人
export const reqDeleteVisitor = (id: number) => request.delete(API.DELETEVISITOR_URL + id)